<%-- 
    Document   : view
    Created on : Jun 2, 2011, 12:05:20 PM
    Author     : C-12®
--%>
<%if (null == session.getAttribute("auth")) {
        response.sendRedirect(request.getContextPath() + "/index.jsp");
    }
%>
<%@ page import="control.*" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ include file="menu.jsp" %>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Personal space</title>
    </head>
    <body>
        <h1>Storage</h1>
        <table>
            <table border='0' >
                <%
                    AccessClass connection = new AccessClass();
                    if (null != session.getAttribute("auth"))
                        if (connection.getFiles(session.getAttribute("uname").toString()).size() > 0) {
                            for (Object j : connection.getFiles(session.getAttribute("uname").toString())) {

                %>
                <tr>
                <form method="post" action ="">
                    <td>Filename: </td><td><%=j.toString()%> </td>
                    <td><input type="HIDDEN" name="FileName" value="<%=j.toString()%>"></td>
                    <td><input type="submit" name="download" value="Download" /></td>
                    <td><input type="submit" name="delete" value="Delete" /></td>
                </form>
                </tr>
                <%
                    }
                } else {%><tr>
                    <td>Directory is empty. </td>
                </tr>
                <%}
                    if (request.getParameter("download") != null) {
                        response.sendRedirect(connection.generateLink(request.getParameter("FileName")));
                    } else if (request.getParameter("delete") != null) {
                        if (!connection.deleteFile(request.getParameter("FileName"))) {
                %><span style="font-weight: bold; color: red">You are not allowed to delete this filed.</span><%                        } else {
                            response.sendRedirect(request.getContextPath() + "/view.jsp");
                        }
                    }

                %>
            </table>
    </body>
</html>
